package com.h3c.nem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eos.common.util.IdWorker;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.h3c.nem.entity.TbFileAcceptRecord;
import com.h3c.nem.mapper.TbFileAcceptRecordMapper;
import com.h3c.nem.service.ITbFileAcceptRecordService;
import com.h3c.nem.dto.TbFileAcceptRecordDTO;
import com.h3c.nem.utils.InitExampleOrderByUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright (C), 2020-2020, h3c
 * FileName: TbFileAcceptRecordServiceImpl
 *
 * @Author: l22886
 * @Date: 2022-01-19
 * Description: tb_file_accept_record serviceImpl
 * Version: 1.0
 */
@Slf4j
@Service
public class TbFileAcceptRecordServiceImpl extends ServiceImpl<TbFileAcceptRecordMapper, TbFileAcceptRecord> implements ITbFileAcceptRecordService {

    @Resource
    private TbFileAcceptRecordMapper tbFileAcceptRecordMapper;



    /**
     * @title: selectFuzzyByDto
     * @description: 模糊查询操作
     * @params: [ dto ]
     * @return: java.util.List
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public List<TbFileAcceptRecordDTO> selectFuzzyByDto(TbFileAcceptRecordDTO dto) {
        //List<TbFileAcceptRecord> list = tbFileAcceptRecordMapper.selectByExample(initFuzzyExample(dto));
        List<TbFileAcceptRecord> list = tbFileAcceptRecordMapper.queryListByFuzzy(JSONObject.parseObject(JSONObject.toJSONString(dto),TbFileAcceptRecord.class));
        return JSONArray.parseArray(JSONArray.toJSONString(list), TbFileAcceptRecordDTO.class);
    }

    /**
     * @title: selectByDto
     * @description: 精确查询操作
     * @params: [ dto ]
     * @return: java.util.List
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public List<TbFileAcceptRecordDTO> selectByDto(TbFileAcceptRecordDTO dto) {
        //List<TbFileAcceptRecord> list = tbFileAcceptRecordMapper.selectByExample(initExample(dto));
        List<TbFileAcceptRecord> list = tbFileAcceptRecordMapper.queryList(JSONObject.parseObject(JSONObject.toJSONString(dto),TbFileAcceptRecord.class));
        return JSONArray.parseArray(JSONArray.toJSONString(list), TbFileAcceptRecordDTO.class);
    }

    /**
     * @title: insertDto
     * @description: 插入操作
     * @params: [ dto ]
     * @return: Integer
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public Integer insertDto(TbFileAcceptRecordDTO dto) {
        //if (null == dto.getId() || "".equals(dto.getId())) {
        //    String pkId = IdWorker.nextId() + "";
        //    dto.setId(pkId);
        //}
        return tbFileAcceptRecordMapper.insertTbFileAcceptRecord(JSONObject.parseObject(JSON.toJSONString(dto), TbFileAcceptRecord.class));
    }

    /**
     * @title: updateDto
     * @description: 修改操作
     * @params: [ dto ]
     * @return: Integer
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public Integer updateDto(TbFileAcceptRecordDTO dto) {
        //if (null != dto && null != dto.getId() && !"".equals(dto.getId())) {
            return tbFileAcceptRecordMapper.updateTbFileAcceptRecord(JSONObject.parseObject(JSON.toJSONString(dto), TbFileAcceptRecord.class));
            //return tbFileAcceptRecordMapper.updateByPrimaryKey(JSONObject.parseObject(JSON.toJSONString(dto), TbFileAcceptRecord.class));
        //} else {
        //    return 0;
        //}
    }

    /**
     * @title: deleteDto
     * @description: 删除操作
     * @params: [ dto ]
     * @return: Integer
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    @Override
    public Integer deleteDto(TbFileAcceptRecordDTO dto) {
        //if (null != dto && null != dto.getId() && !"".equals(dto.getId())) {
            return tbFileAcceptRecordMapper.deleteTbFileAcceptRecord(JSONObject.parseObject(JSON.toJSONString(dto), TbFileAcceptRecord.class));
            //return tbFileAcceptRecordMapper.deleteByPrimaryKey(dto.getId());
        //} else {
        //    return 0;
        //}
    }


    /**
     * @title: initFuzzyExample
     * @description: 初始化 模糊查询 example
     * @params: [ dto ]
     * @return: tk.mybatis.mapper.entity.Example
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    private Example initFuzzyExample(TbFileAcceptRecordDTO dto) {
        Example example = InitExampleOrderByUtils.initExampleOrderBy(TbFileAcceptRecord.class, dto.getOrderBy());
        Example.Criteria criteriaName = example.createCriteria();
        if (null != dto) {
            if (null != dto.getFileId() && !"".equals(dto.getFileId())) {
                criteriaName.andLike("FileId", "%" + dto.getFileId() + "%");
            }
            if (null != dto.getWorkerId() && !"".equals(dto.getWorkerId())) {
                criteriaName.andLike("WorkerId", "%" + dto.getWorkerId() + "%");
            }
            if (null != dto.getAcceptTime() && !"".equals(dto.getAcceptTime())) {
                criteriaName.andLike("AcceptTime", "%" + dto.getAcceptTime() + "%");
            }
            if (null != dto.getFileScore() && !"".equals(dto.getFileScore())) {
                criteriaName.andLike("FileScore", "%" + dto.getFileScore() + "%");
            }
            if (null != dto.getAcceptRemark() && !"".equals(dto.getAcceptRemark())) {
                criteriaName.andLike("AcceptRemark", "%" + dto.getAcceptRemark() + "%");
            }
        }
        return example;
    }

    /**
     * @title: initExample
     * @description: 初始化 精确查询 example
     * @params: [ dto ]
     * @return: tk.mybatis.mapper.entity.Example
     * @createTime: 2022-01-19
     * @version: 1.0
     * @author: l22886
     */
    private Example initExample(TbFileAcceptRecordDTO dto) {
        Example example = InitExampleOrderByUtils.initExampleOrderBy(TbFileAcceptRecord.class, dto.getOrderBy());
        Example.Criteria criteriaName = example.createCriteria();
        if (null != dto) {
            if (null != dto.getFileId() && !"".equals(dto.getFileId())) {
                criteriaName.andEqualTo("FileId", dto.getFileId());
            }
            if (null != dto.getWorkerId() && !"".equals(dto.getWorkerId())) {
                criteriaName.andEqualTo("WorkerId", dto.getWorkerId());
            }
            if (null != dto.getAcceptTime() && !"".equals(dto.getAcceptTime())) {
                criteriaName.andEqualTo("AcceptTime", dto.getAcceptTime());
            }
            if (null != dto.getFileScore() && !"".equals(dto.getFileScore())) {
                criteriaName.andEqualTo("FileScore", dto.getFileScore());
            }
            if (null != dto.getAcceptRemark() && !"".equals(dto.getAcceptRemark())) {
                criteriaName.andEqualTo("AcceptRemark", dto.getAcceptRemark());
            }
        }
        return example;
    }


}
